﻿using System;
using System.Collections.Generic;
using System.Text;
using HAVNet.Core.String;
using HAVNet.Intros.Parsing;


namespace HAVNet.Intros.AST
{
    public class ASTTypeDeclClass : ASTNamespaceTypeDecl
    {
        public          bool                    isPartial       { get; set; }
        public readonly ASTTypeParamList        typeParamList   = new ASTTypeParamList      ();
        public readonly ASTTypeNames            baseTypeNames   = new ASTTypeNames          ();
        public readonly ASTTypeConstraintList   constraints     = new ASTTypeConstraintList ();
        public readonly ASTMemberDecls          members         = new ASTMemberDecls        ();

        public override string ToString ()
        {
            depth++;
            string mods = "";
            if (Mods.has(modifiers, Mods.publicMod))    mods += "public ";
            if (Mods.has(modifiers, Mods.privateMod))   mods += "private ";
            if (Mods.has(modifiers, Mods.internalMod))  mods += "internal ";
            if (Mods.has(modifiers, Mods.protectedMod)) mods += "protected ";
            if (Mods.has(modifiers, Mods.newMod))       mods += "new ";
            if (Mods.has(modifiers, Mods.unsafeMod))    mods += "unsafe ";
            if (Mods.has(modifiers, Mods.staticMod))    mods += "static ";
            if (Mods.has(modifiers, Mods.sealedMod))    mods += "sealed ";
            if (Mods.has(modifiers, Mods.abstractMod))  mods += "abstract ";

            if (isPartial) mods += "partial ";

            string sAttribs = (attrGroups == null) ?
                ""
                :
                Strings.tab(depth) + attrGroups.ToString() + Environment.NewLine;

            string ret = (baseTypeNames.Count > 0) ?
                sAttribs + Strings.tab(depth) + mods + string.Format("class {0}{1}: {2} {3}", name, typeParamList, baseTypeNames, constraints)
                :
                sAttribs + Strings.tab(depth) + mods + string.Format("class {0}{1} {2}", name, typeParamList, constraints);

            ret += Environment.NewLine + Strings.tab(depth) + "{";
            ret += Environment.NewLine + members.ToString();
            ret += Environment.NewLine + Strings.tab(depth) + "}";

            if (hasFinalComma) ret += ";";

            depth--;
            return ret;
        }
    }
}
